package cn.xgl6.springcloud.product.controller;

import cn.xgl6.springcloud.domain.Product;
import cn.xgl6.springcloud.product.service.ProductService;
import cn.xgl6.springcloud.utils.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xgl
 * @create 2020-05-14 15:24
 */
@RestController
@Slf4j
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/product/get/{id}")
    public CommonResult<Product> getProductById(@PathVariable("id") Integer id){
        Product product = productService.getProductById(id);
        log.info("查询到商品为{}",product);
        if (null != product){
            return new CommonResult<>(200,"success",product);
        }else {
            return new CommonResult<>(404,"查询不到该商品",null);
        }
    }
}
